﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using NTwitter;
using System.Collections.ObjectModel;

namespace TwitterClient2.Components
{
    public class PanelNews : Panel
    {
        private RadioButton radioButtonPublic;
        private RadioButton radioButtonFriends;
        private Label labelTimeline;
        private RadioButton radioButtonMentions;
        private PanelNavigation panelNavigation = new PanelNavigation("News", PanelNavigation.PANEL_NEWS);
        private PanelTweetOverview panelTweetOverview = new PanelTweetOverview(200, PanelNavigation.NEWS_USERS);
        private Collection<Status> publicTimeline;
        private Collection<Status> friendsTimeline;
        private Collection<Status> mentionsTimeline;
        private bool publicIsClicked = true;
        private bool friendIsClicked = false;
        private bool mentionsIsClicked = false;
        public PanelNews()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.radioButtonPublic = new System.Windows.Forms.RadioButton();
            this.radioButtonFriends = new System.Windows.Forms.RadioButton();
            this.radioButtonMentions = new System.Windows.Forms.RadioButton();
            this.labelTimeline = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // panelNavagation
            //
            this.panelNavigation.Location = new Point(10, 0);
            //
            // panelTweetOverview
            //
            this.panelTweetOverview.Size = new Size(220, 200);
            this.panelTweetOverview.Location = new Point(10, 60);
            // 
            // radioButtonPublic
            // 
            this.radioButtonPublic.Location = new System.Drawing.Point(10, 40);
            this.radioButtonPublic.Name = "radioButtonPublic";
            this.radioButtonPublic.Size = new System.Drawing.Size(100, 20);
            this.radioButtonPublic.TabIndex = 0;
            this.radioButtonPublic.Click += new EventHandler(this.radioButtonClick);
            this.radioButtonPublic.Text = "Public";
            this.radioButtonPublic.Checked = true;
            // 
            // radioButtonFriends
            // 
            this.radioButtonFriends.Location = new System.Drawing.Point(75, 40);
            this.radioButtonFriends.Name = "radioButtonFriends";
            this.radioButtonFriends.Size = new System.Drawing.Size(100, 20);
            this.radioButtonFriends.TabIndex = 0;
            this.radioButtonFriends.Click += new EventHandler(this.radioButtonClick);
            this.radioButtonFriends.Text = "Friends";
            // 
            // radioButtonMentions
            // 
            this.radioButtonMentions.Location = new System.Drawing.Point(140, 40);
            this.radioButtonMentions.Name = "radioButtonMentions";
            this.radioButtonMentions.Size = new System.Drawing.Size(100, 20);
            this.radioButtonMentions.TabIndex = 0;
            this.radioButtonMentions.Click += new EventHandler(this.radioButtonClick);
            this.radioButtonMentions.Text = "@username";
            // 
            // labelTimeline
            // 
            this.labelTimeline.Location = new System.Drawing.Point(10, 20);
            this.labelTimeline.Font = new Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.labelTimeline.Name = "labelTimeline";
            this.labelTimeline.Size = new System.Drawing.Size(100, 20);
            this.labelTimeline.Text = "Timeline";
            this.Controls.Add(this.panelNavigation);
            this.Controls.Add(this.radioButtonMentions);
            this.Controls.Add(this.radioButtonFriends);
            this.Controls.Add(this.radioButtonPublic);

            this.Controls.Add(this.labelTimeline);
            this.Controls.Add(this.panelTweetOverview);


            this.ResumeLayout(false);

        }

        public void radioButtonClick(object sender, EventArgs args)
        {
            if (sender == this.radioButtonPublic && !this.publicIsClicked)
            {
                this.publicIsClicked = true;
                this.friendIsClicked = false;
                this.mentionsIsClicked = false;
                this.panelTweetOverview.UpdateData(this.publicTimeline);
            }
            else if (sender == this.radioButtonFriends && !this.friendIsClicked)
            {
                this.publicIsClicked = false;
                this.friendIsClicked = true;
                this.mentionsIsClicked = false;
                this.panelTweetOverview.UpdateData(this.friendsTimeline);
            }
            else if (sender == this.radioButtonMentions && !this.mentionsIsClicked)
            {
                this.publicIsClicked = false;
                this.friendIsClicked = false;
                this.mentionsIsClicked = true;
                this.panelTweetOverview.UpdateData(this.mentionsTimeline);
            }
        }

        public void updateData(Collection<Status> publicTimeline, Collection<Status> friendsTimeline, Collection<Status> mentionsTimeline)
        {

            this.publicTimeline = publicTimeline;
            this.friendsTimeline = friendsTimeline;
            this.mentionsTimeline = mentionsTimeline;
            if (this.radioButtonPublic.Checked)
                this.panelTweetOverview.UpdateData(this.publicTimeline);
            else if (this.radioButtonMentions.Checked)
                this.panelTweetOverview.UpdateData(this.mentionsTimeline);
            else
                this.panelTweetOverview.UpdateData(this.friendsTimeline);
        }
    }
}
